<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/8/7
 * Time: 10:36
 */

namespace App\WebSocket\Controller;


use App\Enums\SysKeyEnums;
use App\Enums\UrlEnums;
use EasySwoole\HttpClient\HttpClient;
use EasySwoole\RedisPool\Redis;
use EasySwoole\Socket\AbstractInterface\Controller;

class Live extends Controller
{
    public function all()
    {
        while (1){
            $this->caller()->getClient()->getFd();//获取当前fd
            $info = $this->caller()->getArgs();//获取param传递参数
            list($s1, $s2) = explode(' ', microtime());
            $microtime = (float)sprintf('%.0f', (floatval($s1) + floatval($s2)) * 1000);//毫秒
            $access_key = SysKeyEnums::ACCESS_KEY;
            $secret_key = SysKeyEnums::SECRET_KEY;
            $sign = strtoupper(md5($secret_key.'|'.$microtime));
            $base_url = UrlEnums::WS_FJURL;
            $wsUrl = $base_url."?time={$microtime}&access_key={$access_key}&sign={$sign}";
            $client = new HttpClient($wsUrl);
            $upgradeResult = $client->upgrade();
            $recvFrame = $client->recv();
            var_dump($recvFrame->data);
        }


    }



    public function heartbeat()
    {
        $this->response()->setMessage('PONG');
    }
}